<!doctype html>
<html lang="en" xmlns:v-on="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <script src="vue.js"></script>
</head>
<body>
    <div id="app">
        <input type="text" v-model="text">
        <button @click="handel">提交</button>
        <span  @click="close" v-if="seen">点击关闭</span>
        <ul>
<!--            <li v-for="item in list">{{item}}</li>-->
            <todo-item v-for="(item,index) in list"
                       :content="item"
                       :index="index"
                       @deleteitem="deleteOne"
                       ></todo-item>
        </ul>
    </div>
</body>
<script>

    // Vue.component("TodoItem",{
    //     props:['content'],
    //     template:"<li>{{content}}</li>"
    // })

    var TodoItem ={
        props:['content','index'],
        template:"<li @click='itemOnClick'>{{content}}</li>",
        methods: {
            itemOnClick:function (index) {
                this.$emit('deleteitem',this.index)
            }
        }
    }

    var app = new Vue({
        el:'#app',
        components:{
            TodoItem:TodoItem
        },
        data:{
            list:[],
            text:'',
            seen:true,
        },
        methods:{
            handel:function () {
                this.list.push(this.text)
                this.text = ''
            },
            deleteOne:function (index) {
                this.list.splice(index,1)
            },
            close:function () {
                if (this.seen){
                    this.seen=false
                }
            }
        }
    })
</script>
</html>
